<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../Common/header.jsp"></jsp:include>

<!-- 确认删除模态框 -->


<div id="delDialog" class="modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title">提示</h4>
			</div>
			<div class="modal-body">
				<p>是否确认删除</p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default pull-left"
					data-dismiss="modal">取消</button>
				<button onclick="del()" type="button" class="btn btn-primary">确认</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>

<!-- 确认删除模态框 -->

<!-- 新增模态框 -->


<div id="addDialog" class="modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title">添加职位</h4>
			</div>
			<div class="modal-body">
				<form id="addPositionform" action="<c:url value="/Position/add" />"
							method="post" class="well form-horizontal clearfix">
							<div class="form-group col-xs-12">
								<label class="col-sm-4 control-label" for="name">名称*：</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" id="name" name="name"
										check="require" msg="请输入名称">
								</div>
							</div>

							<div class="form-group col-xs-12">
								<label class="col-sm-4 control-label" for="sort">排序：</label>
								<div class="col-sm-8">
									<input class="form-control" type="text"  id="sequence"
										name="sequence">
								</div>
							</div>

							<div class="form-group col-xs-12" id="role_detail">
								<label class="col-sm-4 control-label" for="is_del">状态：</label>
								<div class="col-sm-8">
									<select class="form-control" name="status" id="status" >
										<option value="true">启用</option>
										<option value="false">禁用</option>
									</select>
								</div>
							</div>
				
						</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default pull-left"
					data-dismiss="modal">取消</button>
				<button type="button" onclick="add()" class="btn btn-primary">确认</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>

<!-- 新增模态框 -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">	
		<section class="content-header">
		<h1>职位管理</h1>
		<ol class="breadcrumb">
			<li><a href="<c:url value="/Admin/index" />"><i
					class="fa fa-dashboard"></i> Home</a></li>

			<c:forEach items="${routers}" var="router">
				<li><i class="${router.icon}"></i><a href="javascript:void(0)">&nbsp&nbsp${router.name
						}</a></li>
			</c:forEach>

		</ol>
	</section>

	<section class="content">
		<div class="page-header"></div>
		<div class="operate panel panel-default">
			<div class="panel-body">
				<div class="pull-right">
					<a class="btn btn-sm btn-primary" data-toggle="modal" data-target="#addDialog" >新增</a> <a
						onclick="save()" class="btn btn-sm btn-primary">保存</a> | <a
						data-toggle="modal" data-target="#delDialog"
						class="btn btn-sm btn-danger">删除</a>
				</div>
			</div>
		</div>
		<!-- 功能操作区域结束 -->
		<!-- 列表显示区域  -->
		<div class="box box-danger">
			<div class="box-header with-border">
				<h3 class="box-title"></h3>

				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool"
						data-widget="collapse">
						<i class="fa fa-minus"></i>
					</button>
					<button type="button" class="btn btn-box-tool" data-widget="remove">
						<i class="fa fa-remove"></i>
					</button>
				</div>
			</div>
			<div class="box-body">
				<div class="row">
					<div class="col-sm-4 sub_left_menu ">
						<table class="table table-bordered" id="rolesTable">
							<thead>
								<tr>
									<th>名称</th>
									<th>状态</th>
									<th>排序</th>
								</tr>
							</thead>
							<tbody>

								<c:forEach items="${positions}" var="position">

									<tr id="${position.id }">
										<td>${position.name }</td>
										<td>${position.status eq true?'启动':'禁用'}</td>
										<td>${position.sequence}</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>

					</div>

					<div class="col-sm-8 last sub_content">
						<form id="updatePositionform" action="<c:url value="/Position/update" />"
							method="post" class="well form-horizontal clearfix">
						
							<div class="form-group col-xs-12">
								<label class="col-sm-4 control-label" for="name">名称*：</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" id="name" name="name"
										check="require" msg="请输入名称">
								</div>
							</div>

							<div class="form-group col-xs-12">
								<label class="col-sm-4 control-label" for="sort">排序：</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" id="sequence"
										name="sequence">
								</div>
							</div>

							<div class="form-group col-xs-12" id="role_detail">
								<label class="col-sm-4 control-label" for="is_del">状态：</label>
								<div class="col-sm-8">
									<select class="form-control" name="status" id="status">
										<option value="true">启用</option>
										<option value="false">禁用</option>
									</select>
								</div>
							</div>
							
							<input type="hidden" id="id" name="id" value="">
						</form>
					</div>

				</div>
			</div>
		</div>

	</section>

</div>
<!-- /.content-wrapper -->
<jsp:include page="../Common/footer.jsp"></jsp:include>
<script type="text/javascript">


$.ajaxSetup({   
    contentType:"application/x-www-form-urlencoded;charset=utf-8",   
    complete:function(XMLHttpRequest,textStatus){ 
      var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头，sessionstatus，  
          if(sessionstatus=="timeout"){ 
              alert("登录超时,请重新登录！");
          //如果超时就处理 ，指定要跳转的页面  
            window.location.reload();   
          }   
       }   
  }); 

	$("#rolesTable tbody tr").click(function() {
		$("#rolesTable tbody tr").attr("class", "");
		$(this).attr("class", "active");

		$.post("<c:url value='/Position/getPosition' />", {
			id : $(this).attr("id"),
		}, function(data, status) {
			
			 
			
			if (data == "" || data == null)
				return;
			data = eval(data);
			$("#updatePositionform #name").val(data.name);
			$("#updatePositionform #status").val(data.status == true ? "true" : "false");
			$("#updatePositionform #sequence").val(data.sequence);
			$("#updatePositionform #id").val(data.id);

		});

	});

	function del() {
		if ($("#id").val() == "") {
			alert("请先选择要删除的职位");
			return;
		}
		window.location.href = "<c:url value="/Position/deleteById" />" + "?id="
				+ $("#id").val();
	}
	function save() {
		if ($("#updatePositionform #id").val() == "") {
			alert("请先选择要更新的职位");
			return;
		}
		
		if ($("#updatePositionform #name").val() == "") {
			alert("职位名不能为空");
			return;
		}
		
		$("#updatePositionform").submit();
	}
	function add() {
		
		if ($("#addPositionform #name").val() == "") {
			alert("职位名不能为空");
			return;
		}
		
		$("#addPositionform").submit();
	}
	
</script>
